package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.TokenVisitor;

public class OTROPFactory extends AbstractTokenVisitorFactory {

	private static OTROPFactory INSTANCE;
	
	private PARAMETRO1Factory parametro1Factory;
	private PARAMETRO2Factory parametro2Factory;
	private PARAMETRO3Factory parametro3Factory;
	
	public static OTROPFactory getInstance() throws Exception {
		if(INSTANCE==null) INSTANCE = new OTROPFactory();
		return INSTANCE;
	}
	
	private Initializer initializer = new Initializer() {
		
		@Override
		public void init() throws Exception {
			initializer = NoOperationInitializer.getInstance();
			parametro1Factory = PARAMETRO1Factory.getInstance();
			parametro2Factory = PARAMETRO2Factory.getInstance();
			parametro3Factory = PARAMETRO3Factory.getInstance();
		}
	};
	
	private OTROPFactory() throws Exception {

	}
	
	@Override
	public TokenVisitor makeChainedVisitor(
			final TokenVisitor siguiente) throws Exception {
		initializer.init();

		return parametro1Factory.makeChainedVisitor(parametro2Factory.makeChainedVisitor(parametro3Factory.makeChainedVisitor(siguiente)));
	
	}
	@Override
	public TokenVisitor makeVisitor() throws Exception {
		initializer.init();

		return parametro1Factory.makeChainedVisitor(parametro2Factory.makeChainedVisitor(parametro3Factory.makeVisitor()));
	}
	
	
}
